<?php

namespace app\adminapi\controller\v1\setting\admin;

use app\adminapi\controller\AuthController;
use app\services\setting\admin\SystemAdminService;
use think\facade\App;

class SystemAdmin extends AuthController
{

    public function __construct(App $app, SystemAdminService $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    public function index()
    {
        $where = $this->request->postMore([
            ['page', 1],
            ['pageSize', 20],
            ['website_id', $this -> website]
        ]);
        return app()->make('json')->successful($this->services->index($where));
    }

    /**
     * 创建用户
     * @return void
     */
    public function create()
    {
        $where = $this->request->getMore([
            ['name',''],
            ['account',1],
            ['password',''],
            ['sex',0],
            ['tel',''],
            ['status',''],
            ['role',''],
        ]);
        return app() -> make('json') -> successful($this -> services -> create($where));
    }

    /**
     * 删除用户
     * @return void
     */
    public function delete()
    {
        $where = $this->request->getMore([
            ['id',''],
        ]);
        return app() -> make('json') -> successful($this -> services -> delete($where));
    }

    /**
     * 更新用户
     * @return void
     */
    public function update()
    {
        $where = $this->request->getMore([
            ['name',''],
            ['account',1],
            ['password',''],
            ['sex',0],
            ['tel',''],
            ['status',''],
            ['role',''],
            ['id',''],
        ]);
        return app() -> make('json') -> successful($this -> services -> update($where));
    }

    /**
     * 搜索角色名称
     * @return mixed
     */
    public function searchAccount(){
        $where = $this->request->postMore([
            ['account',''],
            ['page',1],
            ['pageSize',20],
            ['website_id',$this  -> website],
        ]);
        return app() -> make('json') -> successful($this -> services -> searchAccount($where));
    }

}